package springbootorderrabbitmqproducer.demo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * fanout模式
 */
@Configuration
public class FanoutMqConfiguration {

    // 交换机名字
    String exchangeName = "fanout_order_exchange";
    String smsQueue = "sms.fanout.queue";
    String weiXinQueue = "weiXin.fanout.queue";
    String emailQueue = "email.fanout.queue";

    /**
     * 1 ： 声明注册fanout模式的交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(exchangeName, true, false);
    }



    @Bean
    public Queue smsQueue() {
        return new Queue(smsQueue,true);
    }

    @Bean
    public Queue weiXinQueue() {
        return new Queue(weiXinQueue,true);
    }

    @Bean
    public Queue emailQueue() {
        return new Queue(emailQueue,true);
    }

    // 3 : 完成绑定（队列和交换机绑定）

    @Bean
    public Binding smsBingDing(){
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }



    @Bean
    public Binding weiXinBingDing(){
        return BindingBuilder.bind(weiXinQueue()).to(fanoutExchange());
    }


    @Bean
    public Binding emailBingDing(){
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }


}
